package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-05-08 22:26
 */
public class Offer21_ExchangeArray {
    public int[] exchange(int[] nums) {
        int i = 0, j = nums.length - 1;
        while (i < j) {
            while (nums[i] % 2 == 1 && i < j) {
                i++;
            }
            while (j > i && nums[j] % 2 == 0) {
                j--;
            }
            int tmp = nums[i];
            nums[i] = nums[j];
            nums[j] = tmp;
        }
        return nums;
    }
}
